package it.polimi.traveldream.web;

import it.polimi.traveldream.GestioneUtenteLocal;
import it.polimi.traveldream.UtenteDTO;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;

@ManagedBean
@RequestScoped
//@ViewScoped
public class UserBean {
	
	@EJB
	private GestioneUtenteLocal userMgr;
		
	private UtenteDTO client;
	
	public UtenteDTO getClient() {
		return client;
	}

	public void setClient(UtenteDTO client) {
		this.client = client;
	}
	
	@PostConstruct
	public void init(){
		System.out.print("creazione post construct");
		this.client=new UtenteDTO();
		this.client.setNome((userMgr.findUserByEmail().getNome()));
		this.client.setCognome((userMgr.findUserByEmail().getCognome()));
		this.client.setPassword((userMgr.findUserByEmail().getPassword()));	
		System.out.print(this.client.getNome());
		System.out.print(this.client.getCognome());
		System.out.print(this.client.getPassword());
	 }

	
	public String getName() {
		return userMgr.getUserDTO().getNome();
	}
	
	public String updateUser(){
		System.out.print("update user");
		this.client.setEmail(userMgr.findUserByEmail().getEmail());
		System.out.print(this.client.getEmail());
		System.out.print(this.client.getCognome());
		userMgr.update(client);
		return "index.xhtml?faces-redirect=true";
	  }
}
